package demo;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@WebServlet("/register1.do")
public class diyige extends HttpServlet{
        protected void doGet(HttpServletRequest req, HttpServletResponse resp)
        throws ServletException, IOException {
    resp.setContentType("text/html;charset=UTF-8");
    String username=req.getParameter("username");
    //resp.getWriter().println("页面输入的username="+username);
    String password=req.getParameter("password");
    if(username.length()==0 && password.length()==0){
        resp.getWriter().println("输入有误");
        resp.getWriter().println("<br>");
        resp.getWriter().println("用户名和密码都为空");
    }else if(username.length()!=0 && password.length()==0){
        resp.getWriter().println("输入有误");
        resp.getWriter().println("<br>");
        resp.getWriter().println("密码为空");
    }else if(username.length()==0 && password.length()!=0){
        resp.getWriter().println("输入有误");
        resp.getWriter().println("<br>");
        resp.getWriter().println("用户名为空");
    }else{
        resp.getWriter().println("登录成功");
        resp.getWriter().println("<br>");
        resp.getWriter().println("页面输入的username="+username);
        resp.getWriter().println("<br>");
        resp.getWriter().println("页面输入的password="+password);
    }
    //重定向
//        if(req.getParameter("username").length()!=0){
//            resp.sendRedirect("/success.html");
//        }
    //转发
//        if(req.getParameter("username").length()==0){
//            req.getRequestDispatcher("/error.html").forward(req,resp);
//        }
}}